import { getCommissionGenerateDetailsListByCustId, getCommissionWithdrawDetailsListByCustId } from "../../../api/commissionBalanceController";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    navList:[
      {
        name:'酒钱收入明细',
      },
      {
        name:'酒钱支出明细',
      },
    ],
    navListIndex: 0,

    pageNo: [1,1],
    pageSize: 10,
    isLastPage: [false,false],
    
    detaileList: [[],[]], //明细  兑付
  },
  onLoad(){
    if (this.data.navListIndex == 0) {
      this.getCommissionGenerateDetailsListByCustId()
    } else {
      this.getCommissionWithdrawDetailsListByCustId()
    }
  },
  /**
   * 酒钱支出明细
   */
  async getCommissionWithdrawDetailsListByCustId(){
    let resolve = await getCommissionWithdrawDetailsListByCustId({
      custId: wx.getStorageSync('custId'),
      pageNo: this.data.pageNo[this.data.navListIndex],
      pageSize: this.data.pageSize
    })
    this.setData({
      ['isLastPage['+this.data.navListIndex+']']: resolve.data.isLastPage,
      ['detaileList['+this.data.navListIndex+']']: this.data.detaileList[this.data.navListIndex].concat(resolve.data.list)
    })
  },
  /**
   * 酒钱收入明细
   */
  async getCommissionGenerateDetailsListByCustId(){
    let resolve = await getCommissionGenerateDetailsListByCustId({
      custId: wx.getStorageSync('custId'),
      pageNo: this.data.pageNo[this.data.navListIndex],
      pageSize: this.data.pageSize
    })
    this.setData({
      ['isLastPage['+this.data.navListIndex+']']: resolve.data.isLastPage,
      ['detaileList['+this.data.navListIndex+']']: this.data.detaileList[this.data.navListIndex].concat(resolve.data.list)
    })
  },
  /**
   * 滚动
   */
  bindscrolltolower(e){
    this.data.pageNo[this.data.navListIndex]++
    this.setData({
      ['pageNo['+this.data.navListIndex+']']: this.data.pageNo[this.data.navListIndex]++
    })
    if (this.data.navListIndex==0) {
      if (!this.data.isLastPage[0]) {
        this.getCommissionGenerateDetailsListByCustId()
      }
    }else{
      if (!this.data.isLastPage[1]) {
        this.getCommissionWithdrawDetailsListByCustId()
      }
    }
  },
  /**
   * 切换导航
   */
  changeNav(e){
    let { index } = e.currentTarget.dataset
    this.setData({
      navListIndex: index,
      ['pageNo[0]']: 1,
      ['pageNo[1]']: 1,
      ['detaileList[0]']: [],
      ['detaileList[1]']: [],
    })
    if (this.data.navListIndex == 0) {
      this.getCommissionGenerateDetailsListByCustId()
    } else {
      this.getCommissionWithdrawDetailsListByCustId()
    }
  }
})